// Helper Timer

(function( window, undefined ) {

Helper.Timer = Helper(function( target, time, ticker ) { // Event Helper
	var _target = target;
	var _time = ( time == undefined ) ? 100 : parseInt(time);
	var _ticker = ( typeof ticker == "function" ) ? ticker : null;
	var _timer = undefined;
	var _instance = null;

	return {
		__tick: function() {
			console.log( this, "__tick" );
			
		},
	
		startTimer: function() {
			if ( _timer != undefined ) {
				return;
			};
		
			console.log( this, "startTimer", _time );
			var self = this;
			
			_timer = function() { 
				_instance = setTimeout( function() {
					self.__tick();
					
					if ( _ticker ) _ticker();
					if ( _timer ) _timer();
				}, _time );
			};
			
			_timer();
		},
		
		stopTimer: function() {
			console.log( this, "stopTimer" );
			
			if ( _instance ) {
				clearTimeout(_instance);
			};
			
			_timer = undefined;
			_instance = undefined;
		}
	};
});

})(window);